package web.zipcode;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import common.misc.StringMisc;

import common.command.BaseCommand;

public class ZipcodeSearchAreaDOCommand extends BaseCommand {

    public void execute( HttpServletRequest request, HttpServletResponse response ) throws ZipcodeException {

        String sido = request.getParameter( "sido" );
        String gugun = request.getParameter( "gugun" );
        String dong = request.getParameter( "dong" );

        ZipcodeControl control = new ZipcodeControl();

        ArrayList lstSido = null;
        ArrayList lstGugun = null;
        ArrayList lstDong = null;
        ArrayList list = null;
        
        lstSido = control.searchAllSido();

        if ( StringMisc.isAvailable( sido ) )
            lstGugun = control.searchAllGugun( sido );

        if ( StringMisc.isAvailable( sido ) && StringMisc.isAvailable( gugun ) )
            lstDong = control.searchAllDong( sido, gugun );

        if ( StringMisc.isAvailable( sido ) && StringMisc.isAvailable( gugun ) && StringMisc.isAvailable( dong ) )
            list = control.searchByDong( dong );

        request.setAttribute( "zipcode.search.sido.list", lstSido );
        request.setAttribute( "zipcode.search.gugun.list", lstGugun );
        request.setAttribute( "zipcode.search.dong.list", lstDong );
        request.setAttribute( "zipcode.search.list", list );
        nextPage = "/jsp/zipcode/zipcode_search.jsp";

    } // end method

} // end class